/***************************************************************************
 *   This file is part of KLabeler                                         *
 *   Copyright (C) 2010 by Luca Bellonda                                   *
 *   lbellonda _at_ gmail.com                                              *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

#ifndef KLABELER_APPLICATION_H
#define KLABELER_APPLICATION_H

#include <QTimer>
#include <QSet>
#include <QStringList>
#include <QSignalMapper>

#include <KUniqueApplication>

#include <plasma/plasma.h>

#include "ControlWindow.h"
#include "config-klabeler.h"
#include "configurationManager.h"
#include "nepomukManager.h"
#include "AddTags.h"
#include "AppLog.h"

class KActionCollection;


namespace klabeler
{

class KLabelerApplication : public
#ifdef  TAGGER_UNIQUE_APPL
            KUniqueApplication
#else
            KApplication
#endif
{
    Q_OBJECT
    Q_CLASSINFO("D-Bus Interface", "org.kde.klabeler.App")

    ControlWindow  *_controlWindow ;
    AddTags        *_addTags;

public:
    bool event(QEvent * e);

public Q_SLOTS:
    int prova();

    void assignOtherTags(const QString &activityName, const QString resourcePath);
    void configure();
    bool chooseCurrentProfile();
    /**
      * apply the profile to the resources
      */
    bool applyProfile(const QString &activityName, const QStringList &resourcePath);
    /**
      * gets the tag list assigned to the activity
      */
    QStringList getActivityTags(const QString &activityName, bool &isOk);

private Q_SLOTS:
    void cleanUpAboutToQuit();
    void assignOtherTagsTest();
    void tagsProfileTest();

signals:
    void configurationChanged();
    void profileChanged();

public:

    KLabelerApplication(int argc, char **argv);
    virtual ~KLabelerApplication();
    bool init();

    ConfigurationManager * getConfigurationManager();
    NepomukManager *getNepomukManager();

private:
    bool initInternals();
    void setUpLog();
    bool chooseTheProfile();
    QString getCurrentProfileName() ;
    QStringList getCurrentProfileTags(const QString &activityName, bool &isOk);
    TagProfile* getCurrentProfile();
    bool isProfileIdValid(const QString &id);

    // TEST
    void testMessages();


    void logServiceStart(const QString &service);
    void logServiceEnd(const QString &service, const bool result);
    void logServiceEnd(const QString &service, const int result);

    //------- members ----
    LogParam  logParam;
    ConfigurationManager configurationManager;
    NepomukManager nepomukManager;

};

}

#endif /*KLABELER_APPLICATION_H*/
